package com.yanqu.road.server.cmd.orewar;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.orewar.CrossOreWarMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;


@Cmd(code = Protocol.C_CROSS_OREWAR_PATRONS_SYNC, desc = "门客信息变更同步")
public class CrossPatronsSyncCmd extends CrossUnionCommand {

    private int activityId;
    private int pitId;
    private long pitOwnerUserId;
    private String patronsInfoStr;
    private UserBaseInfo userBaseInfo;
    private int beautySkillAddition;
    private int patronsSkillAddition;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OreWarProto.CrossPatronsAbilityChangeSyncMsg reqMsg = OreWarProto.CrossPatronsAbilityChangeSyncMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        pitId = reqMsg.getPitId();
        pitOwnerUserId = reqMsg.getPitOwnerUserId();
        patronsInfoStr = reqMsg.getPatronsInfoStr();
        userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getPlayerBaseData());
        patronsSkillAddition = reqMsg.getPatronsSkillAddition();
        beautySkillAddition = reqMsg.getBeautySkillAddition();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        List<UserPatrons> userPatronsList = JSON.parseArray(patronsInfoStr,UserPatrons.class);
        CrossOreWarMgr.allPatronsAbilityChange(pitOwnerUserId,userBaseInfo,activityId,pitId,userPatronsList,beautySkillAddition,patronsSkillAddition,groupId);
    }

    @Override
    public void sendData() {

    }

}
